local bianfa = fk.CreateSkill {
  name = "lingling__bianfa",
}

Fk:loadTranslationTable{
  ["lingling__bianfa"] = "变法",
  [":lingling__bianfa"] = "每回合限一次，你的回合内，当一张牌被抵消后，你可以移动场上一张牌。你可以将装备牌当【无懈可击】使用。",

  ["#lingling__bianfa"] = "变法：你可以将装备牌当【无懈可击】使用",
  ["#lingling__bianfa-move"] = "变法：你可以移动场上一张牌",
}

bianfa:addEffect("viewas", {
  anim_type = "control",
  pattern = "nullification",
  prompt = "#lingling__bianfa",
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("nullification")
    card.skillName = bianfa.name
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,
})

bianfa:addEffect(fk.CardEffectCancelledOut, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(bianfa.name) and player.room.current == player and
      #player.room:canMoveCardInBoard() > 0 and player:usedEffectTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = room:askToChooseToMoveCardInBoard(player, {
      skill_name = bianfa.name,
      prompt = "#lingling__bianfa-move",
      cancelable = true
    })
    if #targets > 0 then
      event:setCostData(self, {tos = targets})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = event:getCostData(self).tos
    room:askToMoveCardInBoard(player, {
      skill_name = bianfa.name,
      target_one = targets[1],
      target_two = targets[2],
    })
  end,
})

bianfa:addAI(nil, "vs_skill")

return bianfa
